/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package isasim.instructions;

/**
 *
 * @author Joe
 * This class is the implementation of the ADDS opcode, to add two scalar values
 * and return an integer result.  The result is an integer but how it is represented
 * in the system is up to the caller.
 */
public class ADDS {
    public boolean overflow = false;

    /**
     *
     * @param op1  Operand1 for addition
     * @param op2  Operand2 for addition
     * @return     result of the addition
     */

    public int addScalar(int op1, int op2){
		long result;
                UnsignedHelper uH = new UnsignedHelper();
                System.out.println(op1 + " ---  "+ op2);
                result = uH.UnsignedLongFromInt(op1) + uH.UnsignedLongFromInt(op2);
                if (result > 0xFFFFFFFFL){
                    overflow = true;
                    result = 0;//need to handle this properly
                    System.out.println("overflow");
                } else {
                    result = result & 0xFFFFFFFFL;
                }
                System.out.println(result);
		return (int)result;

	}

}
